#ifndef FOURMAP_HH_
#define FOURMAP_HH_

#include <sys/types.h>
#include "fivetuple.hh"
#include <lagniappe/Mutex.h>
#include <boost/shared_ptr.hpp>

class FourMap
{
  lagniappe::Mutex * mutex;
  tt::FiveTuple core;
  uint32_t count;
  bool set;
  //  uint32_t rand;
public:
  //  FourMap(lagniappe::Mutex * m) : mutex(m), count(0), set(false), rand(0) {}
  FourMap(lagniappe::Mutex * m) : mutex(m), count(0), set(false) {}
  void setCore(tt::FiveTuple & ft) {
    mutex->lock();
    core = ft;
    count++;
    set = true;
    mutex->notifyAll();
    mutex->unlock();
  }
  tt::FiveTuple getCore() {
    mutex->lock();
    while(!set) {
      mutex->wait();
    }
    count++;
    mutex->unlock();
    return core;
  }
  uint32_t getCount() {
    mutex->lock();
    while(!set) {
      mutex->wait();
    }
    int ret = count;
    mutex->unlock();
    return ret;
  }
//   uint32_t getRand() {
//     mutex->lock();
//     while(!set) {
//       mutex->wait();
//     }
//     uint32_t ret = rand;
//     mutex->unlock();
//     return ret;
//   }
//   void setRand(uint32_t r) {
//     mutex->lock();
//     while(!set) {
//       mutex->wait();
//     }
//     rand = r;
//     mutex->unlock();
//   }
    
};

typedef boost::shared_ptr<FourMap> FourMap_p;

#endif // FOURMAP_HH_
